package com.dandelion.admin.controller;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Allen on 2016/7/15.
 */

@Controller
public class MainController {
    @RequestMapping("/main")
    public ModelAndView hello(HttpServletRequest request) {
        ModelAndView mv = new ModelAndView("main");
        UserDetails details = (org.springframework.security.core.userdetails.UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        mv.addObject("u", details);
        return mv;
    }

    @RequestMapping("/heartbeat")
    public void heartBeat(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.getWriter().write("OK");
    }
}
